package client_cmd;

import java.io.IOException;

import client_entity.Group;
import client_entity.User;

public class Modify_Groups extends Command {
	
	private static final int SAVEGROUP = 4;
	
	private Group current_group;
	
	public Modify_Groups(User user)
	{
		super(user);
	}
	
	//添加好友
	public boolean add_member(int user_number)
	{
		current_group.getGroup_member().add(user_number);
		current_group.setGroup_size(current_group.getGroup_size()+1);
		return send_user();
	}
	
	//删除好友
	public boolean delete_member(int user_number)
	{
		current_group.getGroup_member().remove((Object) user_number);
		current_group.setGroup_size(current_group.getGroup_size()-1);
		return send_user();
		
	}
	
	//重命名组
	public boolean rename_group(String group_name)
	{
		current_group.setGroup_name(group_name);
		return send_user();
	}
	
	//删除组
	public boolean delete_group()
	{
		user.getFriends().remove(current_group);
		return send_user();
	}
	
	//将某用户移动到某组
	public boolean move(int user_number,Group finalLocation)
	{
		current_group.getGroup_member().remove((Object) user_number);
		current_group.setGroup_size(current_group.getGroup_size()-1);
		finalLocation.getGroup_member().add(user_number);
		finalLocation.setGroup_size(current_group.getGroup_size()+1);
		return send_user();
	}
	
	//增加组（组名）
	public boolean add_group(String group_name)
	{
		Group group = new Group(group_name);
		user.getFriends().add(group);
		return send_user();
	}

	public void setCurrent_group(Group current_group) {
		this.current_group = current_group;
	}

	//向服务器发送已经编辑好的信息
	private boolean send_user()
	{
		try {
			connector.send(SAVEGROUP, user);
		}catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
		return (Boolean) connector.recieve();
	}
	
	
}
